﻿/* Write a program for extracting all email addresses from given text. All substrings that match the format <identifier>@<host>…<domain> should be recognized as emails. */

using System;
using System.Text.RegularExpressions;

namespace _18.ExtractEmails
{
    class ExtractEmails
    {
        static void Main()
        {
            string str = "alabala@alabala.com test@yahoo.com fpqojf qpofj pofjq test@myserv.com test@subdomain.myserv.com pfowj fpwojfqwpof w lmao@lmao.lmao";
            Regex r = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);
            if (!r.IsMatch(str)) Console.WriteLine("No emails found.");
            else
            {
                Console.WriteLine("Extracted email list: \r\n");
                foreach (Match m in r.Matches(str))
                {
                    Console.WriteLine(m.Groups[0].Value.ToString());
                }
            }
        }
    }
}
